package com.zige.zige.activity.main;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

/**
 * Created by sony-song on 2015/3/18.
 */
public class FragmentAdapter extends FragmentPagerAdapter {

    public final static int TAB_TODAY = 0;
    public final static int TAB_YESTERDAY = 1;
    public final static int TAB_BEFOREYSERDAY = 2;
    public final static int TAB_SUM = 3;

    public Fragment fragment_today, fragment_yesterday, fragment_beforyesterday;

    public FragmentAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int i) {
        Fragment fragment;
        switch (i) {
            default:
            case TAB_TODAY:
                if (fragment_today == null) {
                    fragment_today = new TodayFragment();
                }
                fragment = fragment_today;
                break;
            case TAB_YESTERDAY:
                if (fragment_yesterday == null) {
                    fragment_yesterday = new YesterdayFragment();
                }
                fragment = fragment_yesterday;
                break;
            case TAB_BEFOREYSERDAY:
                if (fragment_beforyesterday == null) {
                    fragment_beforyesterday = new BeforeYesterdayFragment();
                }
                fragment = fragment_beforyesterday;
                break;

        }
        return fragment;
    }

    @Override
    public int getCount() {
        return TAB_SUM;
    }
}
